<?php

$page = "Schedule";

include_once("common.php");


gpp_print_header($page, "");

// If the user is logged in, we want to send them to the page where
// they can actually use the application.
if(!gpp_is_authenticated())
{
	gpp_redirect("entrance");
}

function display_course_checkbox($acronym, $course_id, $message="")
{
	$json = get_course_json_acronym($acronym, $course_id); 
	
	$course = json_decode($json);
	
	echo '<span class="course_checkbox_span"><input class="course_checkbox" type="checkbox" id="' . $acronym . $course_id . "\" value='" . $json . "' />";
	echo '<label title="' . $course->description . ' " for="'. $acronym . $course_id . '">'. $acronym . " " . $course_id . " " . $course->title . '</label>';
    echo '</span>';
    
}

$acronyms = get_acronyms_for_display();

?>

<script type="text/javascript">

$(document).ready(function(){

	reset_stored_history();
  
});


$(function() {
	$(".save_history").click(function(){
		var answer = confirm("Are you sure you wish to attempt to save this as your history?");
		if(answer)
		{
			save_history();
		}
	})
})


$(function() {
	$(".reset_history").click(function() {
		var answer = confirm("Are you sure you wish to reset your schedule to the stored one?");
		if(answer)
		{
			reset_stored_history();
		}
	})
})

function update_courses_from_checkboxes()
{
	semester = "-1";
	    
	schedule["s" + semester].clean_schedule();
	
	$(".course_checkbox").each(function() {
		
		if($(this).attr('checked'))
		{
		    course = JSON.parse($(this).attr('value'));
			add_course_to_semester_no_check(semester, course);
		}
		
	})

}

$(function() {
	$(".course_checkbox").change(function() {
		update_courses_from_checkboxes();
		
	})
})


</script>

<div id="head">
<p class="noprint">To edit your course history, use the fields below.</p>

<h2><?php echo $message ?></h2>

</div>
<div id="checkbox_cont">
	<div id="checkboxes">
	
	<div class="noprint">
        <input type="button" class="save_history" value="Save History" />
        <input type="button" class="reset_history" value="Reset History" />
        <input type="button" value="Print This Page" onclick="window.print();return false;" />
    </div>

	<!-- enter the major requirements here -->
	
	<?php include_once('greensheets/' . $_SESSION['pursuing'] . '.php') ?>
	
	<!-- end major requirements -->
	
	</div>
</div>

<div id="history_box">
	<div><h2>Selected Courses</h2>
		<table semester="s_-1" id="semester_s-1" class="semester_list"><thead><tr class="semester_cap"><td style="width:400px">Course</td><td style="width:50px">Credits</td><td style="width:50px">&nbsp;</td></tr></thead>
	<tbody>
		<!-- Put in original courses here, but they need to be loaded into a JavaScript object and put here
			automagically -->
		
		</tbody>
		</table>
    </div>



	<div><h2>Other Courses</h2>
		<table semester="s_-2" id="semester_s-2" class="semester_list"><thead><tr class="semester_cap"><td style="width:400px">Course</td><td style="width:50px">Credits</td><td style="width:50px">&nbsp;</td></tr></thead>
	<tbody>
		<!-- Put in original courses here, but they need to be loaded into a JavaScript object and put here
			automagically -->
		
		</tbody>
		</table>
	
        <div class="noprint">Add Course: <select class="acronym" title="-2">
                        <?php echo $acronyms; ?>
                    </select>
                    <select id="numbers-2"></select><input type="button" size="1" title="-2" value="+" class="add_class" name="add_class_-2" id="add_class_-2" />
        </div>
	
	</div>
	
	<input type="button" class="save_history noprint" value="Save History" /><br />
</div>

<?php 

gpp_print_footer();

?>